package com.sky.controller.common;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.common.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理控制器
 *
 * @Author: Zhy
 * @Date: 2025-01-19 21:20
 * @Version: 1.0
 */
@Slf4j
@RequestMapping("/admin/dish")
@RestController
@Api(tags = "菜品管理")
@RequiredArgsConstructor
public class DishController {
	private final DishService dishService;

	/**
	 * 新增菜品
	 *
	 * @return:
	 * @param:
	 */
	@PostMapping
	@ApiOperation("新增菜品")
	public Result<String> addDish(@RequestBody DishDTO dishDTO) {
		log.info("新增菜品, dish:{}", dishDTO);

		return dishService.addDish(dishDTO);
	}

	/**
	 * 分页查询菜品
	 *
	 * @return:
	 * @param:
	 */
	@GetMapping("/page")
	@ApiOperation("分页查询菜品")
	public Result<PageResult<DishVO>> pageDish(DishPageQueryDTO dishPageQueryDTO) {
		log.info("分页查询菜品, dishPageQueryDTO:{}", dishPageQueryDTO);

		return dishService.pageQueryDish(dishPageQueryDTO);
	}

	/**
	 * 批量删除菜品
	 *
	 * @return:
	 * @param:
	 */
	@DeleteMapping
	@ApiOperation("删除菜品")
	public Result<String> deleteDishById(@RequestParam(name = "ids") List<Long> ids) {
		log.info("删除菜品, ids:{}", ids);

		return dishService.deleteDishById(ids);
	}

	/**
	 * 根据ID查询菜品及口味信息
	 *
	 * @return:
	 * @param:
	 */
	@GetMapping("/{id}")
	@ApiOperation("根据ID查询菜品及口味信息")
	public Result<DishVO> getDishById(@PathVariable("id") Long id) {
		log.info("根据ID查询菜品, id:{}", id);

		return dishService.getDishAndFlavorsById(id);
	}

	/**
	 * 更新菜品信息及其口味信息
	 *
	 * @return:
	 * @param:
	 */
	@PutMapping
	@ApiOperation("更新菜品信息及其口味信息")
	public Result<String> updateDishAndFlavors(@RequestBody DishDTO dishDTO) {
		log.info("更新菜品信息及其口味信息, dishDTO:{}", dishDTO);

		return dishService.updateDishAndFlavors(dishDTO);
	}

	/**
	 * 查询所有菜品
	 *
	 * @return:
	 * @param:
	 */
	@GetMapping("/list")
	@ApiOperation("查询所有菜品")
	public Result<List<Dish>> findAllDish(@RequestParam Long categoryId) {
		log.info("查询所有菜品, categoryId:{}", categoryId);

		return dishService.findAllDish(categoryId);
	}

	/**
	 * 更新菜品状态
	 *
	 * @return:
	 * @param:
	 */
	@PostMapping("/status/{status}")
	@ApiOperation("更新菜品状态")
	public Result<String> updateDishStatus(@PathVariable("status") Long status, @RequestParam(name = "id") Integer id) {
		log.info("更新菜品状态, status:{}, id:{}", status, id);

		return dishService.updateDishStatus(status, id);
	}

}
